#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
  int val;
  struct Node *next;
} Node, *List;
int insert(List l, int val, int pos) {
  if (pos < 1) {
    perror("negative index");
    return -1;
  }
  Node *p = l;
  for (int index = 1; index < pos; index++, p = p->next) {
    if (p == NULL) {
      perror("index out of bounds");
      return -1;
    }
    printf("skipping node valued %d", p->val);
  }
  printf("inserting after node valued %d\n", p->val);
  Node data = {val, p->next};
  Node *nNew = malloc(sizeof(Node));
  if (nNew == NULL) {
    perror("malloc failed");
    return -1;
  }
  *nNew = data;
  p->next = nNew;
  return pos;
}
int reverse(List l) {
  Node lNew = {.next = 0};
  for (;;) {
    Node *p = l->next;
    if (!p) {
      l->next = lNew.next;
      return 0;
    }
    l->next = p->next;
    p->next = lNew.next;
    lNew.next = p;
  }
}
int show(List l) {
  for (Node *p = l->next; p; p = p->next) {
    printf("%d\t", p->val);
  }
  printf("\n");
  return 0;
}
int main() {
  Node head = {0, 0};
  //   head.next = NULL;
  int pos, value;
  while (scanf("%d %d", &pos, &value) == 2) {
    insert(&head, value, pos);
    show(&head);
  }
  reverse(&head);
  show(&head);
  return 0;
}
